<?php
class Core_Model_Character_Params_Mapper	
	extends Core_Model_Db_Mapper_Abstract
{
	protected $_dbTableClass = 'Core_Model_Character_Params_Table';
	
	protected $_tablePre	= 'param_';
	
	public function findById(Core_Model_Character_Param $param)
	{
		if (null === $param->getId())
		{
			throw new Core_Model_Character_Params_Exception('Id Set');	
		}
		
		$where	= $this->_getAdapter()
			->where($this->_tablePre . 'id = ?', $param->getId());
		
		$res	= $this->_queryWithCache($where);
		
		if (count($res) < 1)
		{
			throw new Core_Model_Character_Params_Exception('Invalid Id');
		}
		
		if (count($res) > 1)
		{
			throw new Core_Model_Character_Params_Exception('Fatal Error: too many results');
		}
		
		$res	= $res->toArray();
		$this->mapToParam($res[0], $param);
	}
	
	public function fetchAll()
	{
		$res	= $this->_queryWithCache($where);
		$res	= $res->toArray();
		
		foreach($res as $row)
		{
			$param	= new Core_Model_Character_Param();
			$this->mapToParam($row, $param);	
		}
	}
	
	protected function mapToParam($row, Core_Model_Character_Param $param)
	{
		$param->setOptions(array('id'	=> $row[$this->_tablePre . 'id'],
								'name'	=> $row[$this->_tablePre . 'name'],
								'type'	=> $row[$this->_tablePre . 'type']));
	}
}